/*
 * Copyright (c) 2020 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.afollestad.commons.folderselector;

import com.afollestad.commons.ResourceTable;
import ohos.agp.components.*;
import ohos.app.Context;

public class MainListProvider extends BaseItemProvider {
    private CharSequence[] listItems;
    private Context mContext;

    MainListProvider(Context context, CharSequence[] listItems) {
        mContext = context;
        this.listItems = listItems;
    }

    void setUpdatedItems(CharSequence[] listItems) {
        this.listItems = listItems;
        notifyDataChanged();
    }

    @Override
    public int getCount() {
        return listItems.length;
    }

    @Override
    public Object getItem(int i) {
        return listItems[i];
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        if (component == null) {
            component = LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_md_text_list_item, componentContainer, false);
        }
        ((Text) (component.findComponentById(ResourceTable.Id_txtListItem))).setText((String) getItem(i));
        return component;
    }
}